<div class="page-content" >
	<div class="panel panel-default">
		<div class="panel-heading">
			<ul class="breadcrumb">
				<li><a  href="<{:addons_url('index')}>">区块列表</a> </li>
				<li class="active">添加区块</li>
			</ul>
		</div>
		<div class="panel-body">
			<form id="myform" method="post" class="form-horizontal" action="<{:addons_url('add_do')}>">
				<input type="hidden" name="id" value="<{$data.id}>">
				<div class="form-group">
					<label for="input-title"  class="col-sm-2 control-label">调用代码</label>
					<div class="col-sm-9">
						<input  type="text" class="form-control" id="name" name="name" value="<{$blocks_name}>">
					</div>
				</div>
				<div class="form-group">
					<label for="input-title"  class="col-sm-2 control-label">名称</label>
					<div class="col-sm-9">
						<input  type="text" class="form-control" id="title" name="title" value="<{$data.title}>">
					</div>
				</div>
				<div class="form-group">
					<label for="input-title"  class="col-sm-2 control-label">描述</label>
					<div class="col-sm-9">
						<textarea class="form-control"  name="info"><{$data.info}></textarea>
					</div>
				</div>
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">类型</label>
					<div class="col-sm-9">
						<select name="type" onchange="set_blocks_image(this)">
							<volist name="blocks_type" id="vo"> <option 
								<if condition="$key eq $data['type']">selected="selected"</if>
								 value="<{$key}>"><{$vo}>
								</option>
							</volist>
						</select>
					</div>
				</div>
				<div class="form-group set_blocks blocks_image" style="display:none">
					<label for="input-title" class="col-sm-2 control-label">设置</label>
					<div class="col-sm-9"> <a data-type="modal" target="_blank"  w=0.8 href="<{:addons_url('blocks_image',array('blocks_name'=>$images_blocks_name))}>"  class="btn btn-primary btn-sm">设置</a> </div>
				</div>
				
				<div class="form-group set_blocks blocks_topic" style="display:none">
					<label for="input-title" class="col-sm-2 control-label">设置</label>
					<div class="col-sm-9"> <a data-type="modal" target="_blank" w=0.8 href="<{:addons_url('blocks_image',array('blocks_name'=>$images_blocks_name,'tpl'=>'topic'))}>"  class="btn btn-primary btn-sm">设置</a> </div>
				</div>
				
				
				<div class="form-group" id="tpl_content">
					<label for="input-title" class="col-sm-2 control-label">模板</label>
					<div class="col-sm-9">
						<select name="tpl_type" onchange="select_tpl(this)">
							<volist name="tpl_list" id="vo"> <option 
								<if condition="$vo['name'] eq $data['tpl_type']">selected="selected"</if>
								 value="<{$vo['name']}>"><{$vo['title']}>
								</option>
							</volist>
						</select>
					</div>
				</div>
				
				<div class="form-group" id="data_tpl_content">
					<label for="input-title"  class="col-sm-2 control-label">模板内容</label>
					<div class="col-sm-9">
						<textarea class="form-control"  name="tpl"><{$data.tpl}></textarea>
					</div>
				</div>
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">启用</label>
					<div class="col-sm-9" style="margin-top:5px" >
						<label>
							<input type="radio"  name="enable" value="1" checked="checked"  />
							启用&nbsp; </label>
						<label> <input type="radio"  name="enable" value="2" 
							<if condition="$data['enable'] eq 2">checked="checked" </if>
							/>不启用</label>
					</div>
				</div>
				<div class="form-group">
					<label for="input-title" class="col-sm-2 control-label">是否缓存</label>
					<div class="col-sm-9" style="margin-top:5px" >
						<label>
							<input type="radio"  name="cache" value="1" checked="checked"  />
							是&nbsp; </label>
						<label> <input type="radio"  name="cache" value="2" 
							<if condition="$data['cache'] eq 2">checked="checked" </if>
							/>不缓存</label>
					</div>
				</div>
				<div class="form-group">
					<div class="col-sm-offset-2 col-sm-9">
						<button type="submit" class="btn btn-primary">保存</button>
						<a data-type='modal' href="<{:addons_url('viwe',array('name'=>$data['name']))}>"   class="btn btn-primary">预览</a> </div>
				</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">

$(function(){
	var editor ;
		editor = KindEditor.create('textarea[name="tpl"]', {
			allowImageUpload : true,
			newlineTag : "br",
			uploadJson : '<{:U("Kindeditor/uploadJson")}>',
			//urlType : 'domain',
			filterMode:false,
			formatUploadUrl:false,
			wellFormatMode:false,

		});

})

</script> 
<script>

select_tpl($("[name='tpl_type']"));
set_blocks_image($("[name='type']"));
function select_tpl(obj){
	 var v=$(obj).val();
	 if(v=="diy_tpl"){
	 	$("#data_tpl_content").show();
		 $(".ke-container").removeAttr("style");
	 }else{
		 $("#data_tpl_content").hide();
	 }
} 
 
function set_blocks_image(obj){
	var v=$(obj).val();
	$(".set_blocks").hide();
	$(".blocks_"+v).show();
	if(v=="image" || v=="topic" || v=="none"){//需要显示选择模板
	  $("#tpl_content").show();
			select_tpl($("[name='tpl_type']"));
	}else{
	  $("#tpl_content").hide();
	}
	
	if(v=="PHP" || v=="widget"){//php需要显示编辑器
		$("#data_tpl_content").show();
		 $(".ke-container").removeAttr("style");
	}
	
	
} 
$(function(){
    $(".form-horizontal").bootstrapValidator({
        message: '您填入的值不合法',
        fields:{
            name: {
                message: '代码名称',
                validators: {
                    notEmpty: {
                        message: '代码名称不能为空'
                    },
                }
            },
			title: {
                message: '标题不能为空',
                validators: {
                    notEmpty: {
                        message: '标题不能为空'
                    },
                }
            },
			
        }
    });
	
 
});
 </script> 